package com.pet.server.ext.action.product;

import java.util.List;

import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.Result;
import com.pet.server.ext.constants.BaseAttribute;
import com.pet.server.ext.data.Constant;
import com.pet.server.ext.data.ConstantUi;
import com.pet.server.ext.data.Image;
import com.pet.server.ext.data.ProductInfo;
import com.pet.server.ext.service.ProductService;
import com.pet.server.ext.service.SystemService;
import com.pet.server.ext.service.UserService;
import com.pet.server.ext.util.JsonUtil;
import com.pet.server.ext.util.NumberUtil;
import com.pet.server.ext.util.Parameters;
import com.pet.server.ext.util.StringUtil;
import com.pet.server.ext.util.cache.ConstantUiUtil;
import com.pet.server.ext.util.cache.ConstantUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class Category extends ActionBase{

	private Integer product_id;
	public Category(){
		 needCheckAuth =false;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {	
	
		
		
	}
	
	@Override
	public Result invokeService() throws ApiError {
		Result result = new Result();
		ConstantUi con = ConstantUiUtil.getInstance().findConstant("088");
		JSONArray array = new JSONArray();
		if(null!=con){
			array = toArray(con.list);
		}
		result.put("data",array);
		return result;
	}
	
	//img_path,color_value,pet_breeds,pet_cate,pet_import
	public JSONArray toArray(List<ConstantUi> list){
		JSONArray array = new JSONArray();
		for(ConstantUi cons:list){
			JSONObject o = new JSONObject();
			o.put("cate_name",cons.ui_name);
			o.put("cate_code", cons.code);
			o.put("ico_path", null);
			o.put("img_path", cons.img_path);
			o.put("color_value",cons.color_value);
			o.put("sub_category", toArray(cons.list));
			array.add(o);
		}
		return array;
	}
	
	
	
	
}
